package com.cdx.dxmall.product.exception;

import com.cdx.dxmall.common.exception.BizCodeEnume;
import com.cdx.dxmall.common.utils.R;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author chedx
 * @data 2021/1/7 12:10 AM
 */
@RestControllerAdvice(basePackages = "com.cdx.dxmall.product.controller")
public class GlobalHandlerExceptionAdvice {
    @ExceptionHandler
    public R handlerOneException(MethodArgumentNotValidException e) {
        e.getBindingResult();
        return R.error(BizCodeEnume.UNKNOW_EXCEPTION.getCode(),BizCodeEnume.UNKNOW_EXCEPTION.getMsg());
    }

    @ExceptionHandler
    public R handlerException(Throwable e) {
        return R.error(BizCodeEnume.UNKNOW_EXCEPTION.getCode(),BizCodeEnume.UNKNOW_EXCEPTION.getMsg()).put("error",e.getMessage());
    }


}
